<?php
/**
* @desc 广告表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class TripForm extends BaseForm
{
	public $trip_name;
	public $hotal;
	public $sort;
	public $hotal_start;
	public $trip_pro;
	public $hot_pro;
	public $is_show;
	public $food;
	public $spot;
	public $detail;
	public $hotal_image;
	public $goods_id;
	//表单规则
	public function rules()
	{
		return array(
			array('trip_name, sort, hotal, food, hotal_start, trip_pro, hotal_image', 'required', 'message'=>'必填字段不能为空'),
			array('trip_name', 'unique' , 'on'=>'add', 'className'=>'Trip', 'message'=>'行程名称已存在'),
			array('sort, hotal_start, goods_id', 'numerical', 'message'=>'排序必须为数字'),
			array('is_show', 'boolean', 'message'=>'是否显示为布尔值'),
			array('hot_pro, spot, detail','default', 'setOnEmpty'=>true, 'value'=>''),
		);
	}
	//写入数据
	public function saveData(){
		$model = new Trip;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = $this->attributes;
		$data['author'] = $userInfo['username'];
		$data['hotal_image'] = json_encode($data['hotal_image']);
		return $model->insertTrip($data);
	}
	//修改数据
	public function editData($id){
		$data = $this->attributes;
		$data['hotal_image'] = json_encode($data['hotal_image']);
		$model = new Trip;
		return $model->editTrip($id, $data);
	}
}
